package com.nlx.notes.module.controller;

import com.nlx.notes.module.bean.dto.FlowPageQueryDTO;
import com.nlx.notes.module.bean.dto.FlowSaveDTO;
import com.nlx.notes.module.bean.vo.DayFlowViewVo;
import com.nlx.notes.module.bean.vo.PageResultVo;
import com.nlx.notes.module.bean.vo.ResultVO;
import com.nlx.notes.module.core.util.JSONUtils;
import com.nlx.notes.module.service.ITransactionsService;
import com.nlx.notes.support.context.UserHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author nlx
 * @since 2024-12-15
 */
@Slf4j
@RestController
@RequestMapping("/transactions")
@RequiredArgsConstructor(onConstructor_ =@Autowired)
public class TransactionsController {

    final ITransactionsService transactionsService;

    /**
     * 保存流水
     * @param flowSaveDTO 流水参数
     * @return String 流水id
     */
    @PostMapping(value = "/saveFlow")
    public ResultVO  saveFlow(@RequestBody @Validated FlowSaveDTO flowSaveDTO){
        log.info("新增流水，参数：{}", JSONUtils.toString(flowSaveDTO));
        flowSaveDTO.setUserId(UserHolder.getUserContext().getId());
        return  ResultVO.success(transactionsService.saveFlow(flowSaveDTO));
    }


}
